package com.gxa.saas.portal.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.saas.core.entity.dto.luoj.TbAddressDTO;
import com.gxa.saas.portal.mapper.AddressMapper;
import com.gxa.saas.portal.service.AddressService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

@Service
@Validated
@Transactional(rollbackFor = Throwable.class)
public class AddressServiceImpl extends ServiceImpl<AddressMapper,TbAddressDTO> implements AddressService {

    @Resource
    private AddressMapper addressMapper;

    @Override
    public List<TbAddressDTO> queryAllAddress(@Validated @NotNull(message = "用户id不能为空")Integer userId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",userId);
        queryWrapper.ne("ad_status",-1);
        List list = addressMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public Boolean updateAddressStatus(@Validated TbAddressDTO tbAddressDTO) {
//        UpdateWrapper updateWrapper = new UpdateWrapper();
//        updateWrapper.set("ad_status",tbAddressDTO.getAdStatus());
//        updateWrapper.eq("user_id",tbAddressDTO.getUserId());
        boolean b = this.saveOrUpdate(tbAddressDTO);
        return b;
    }

    @Override
    public TbAddressDTO getAddressById(@NotNull(message = "用户id不能为空") Integer addressId) {
        TbAddressDTO byId = this.getById(addressId);
        return byId;
    }
}
